<?php

namespace app\index\controller;
use pan\AjaxMessage;
use think\Controller;
use thans\jwt\facade\JWTAuth;
class Login extends Controller
{
     public  function index(){
         $username=input('param.username');
         $password=input('param.password');
         $password=md5($password);
         try{
             $res=db('account')->field('id,name')
                 ->where('name',$username)
                 ->where('password',$password)
                 ->where('delStatus',0)
                 ->where('enabled',1)
                 ->findOrFail();
//             dump($res['id']);
//             exit;
            $res['token'] = JWTAuth::builder(['id' => $res['id'],'name'=>$res['name']]);
            return  AjaxMessage::success($res);
         }catch (\Exception $e){
             return AjaxMessage::error($e->getMessage());
         }


     }
}
